<template>
  <div class="box">
    <el-form size="medium" label-width="100px" >
      <el-form-item label="分类层级设置">
        <el-radio-group v-model="obj.level">
          <el-radio :label="1">一级</el-radio>
          <el-radio :label="2">二级</el-radio>
          <el-radio :label="3">三级</el-radio>
        </el-radio-group>
      </el-form-item>

      <el-form-item label="风格">
        <div class="sl">
          <div :class="'ss ' + (item == obj.type ? 'on' : '') + ''" v-for="item in ['1', '2', '3', '4'].slice(0, obj.level == 3 ? 3 : 4)" :key="item">
            <div class="online">使用中</div>
            <div class="mask">
              <div class="mc"><el-button type="primary" @click="selectThis(item)">启用样式</el-button></div>
            </div>
            <img :src="require('@/assets/images/category_' + obj.level + '_' + item + '.png')" />
          </div>
        </div>
      </el-form-item>

      <el-form-item><el-button type="primary" size="medium" @click="saveData">确定</el-button></el-form-item>
    </el-form>
  </div>
</template>
<script>
import {editLevel} from '@/api/mall/product';
export default {
  name: 'cateLevel',
  data() {
    return {
      pics: [],
      loading: false,
      obj: {
        level: this.level,
        type: this.type
      }
    };
  },
  props: {
    level: {
      type: Number,
      default: 1
    },
    type: {
      type: String,
      default: '1'
    }
  },
  mounted() {
    //this.obj.level = this.level;
  },
  watch: {
    'obj.level': {
      handler: function() {
        this.obj.type = null;
        // if(this.obj.level == 3 && this.obj.type == '4'){
        //   this.obj.type = '3';
        // };
      }
    }
  },
  methods: {
    //选择风格
    selectThis(type) {
      this.obj.type = type;
    },
    //保存数据
    saveData() {
      if(!this.obj.type){
        this.$message('请先选择风格')
        return false
      }
      this.$confirm('是否确定保存层级操作?')
        .then(_ => {
          this.isloading = true;
          editLevel(this.obj).then(res => {
            this.isloading = false;
            this.$emit('nlevel', this.obj);
          });
        })
        .catch(_ => {});
    }
  }
};
</script>

<style lang="scss" scoped>
.el-input {
  width: 270px;
}

.box {
  width: 100%;
  /*padding: 60px;
  height: calc(100vh - 77px);
  overflow: scroll;*/
}

//风格样式
.sl {
  display: flex;

  .ss {
    // flex-shrink: 0;
    // flex-wrap: wrap;
    width: 252px;
    height: 448px;
    margin-right: 20px;
    border: 1px solid #ebeef5;
    position: relative;
    cursor: pointer;
    overflow: hidden;

    &:not(.on):hover {
      .mask {
        display: block;
      }
    }

    &.on {
      border-color: #409eff;

      .online {
        display: block;
      }
    }

    .online {
      display: none;
      position: absolute;
      width: 120px;
      height: 28px;
      line-height: 28px;
      text-align: center;
      font-size: 12px;
      color: #fff;
      background-color: #409eff;
      transform: rotate(-45deg);
      left: -35px;
      top: 10px;
    }

    .mask {
      position: absolute;
      left: 0;
      top: 0;
      width: 252px;
      height: 448px;
      background-color: rgba(0, 0, 0, 0.2);
      display: none;

      .mc {
        width: 252px;
        height: 448px;
        display: flex;
        justify-content: center;
        align-items: center;
      }
    }

    img {
      width: 250px;
      display: block;
    }
  }
}
</style>
